//=============================================================================
// SentinelUpgrade - A bit like an Inventory item.
//=============================================================================
class SentinelUpgrade extends Actor;

var Sentinel Sentinel;
var SentinelUpgrade NextUpgrade; // Next in linked list of upgrades.

var() int AmmoCost;
var() string UpgradeName;
var() string Description; //This is in here to work around servers not pushing int files. This means that clients can only see English (or whatever language this variable is in), sorry.
var() sound ActivateSound;

var bool bFitsFloor, bFitsCeiling; //These control which type of cannon the upgrade can be added to, e.g. the standard weapons don't fit ceiling Sentinels.
var bool bInvasionOnly; //Only allow in Invasion, e.g. Super Shock Rifle.

replication
{
	reliable if(Role == ROLE_Authority)
		Sentinel, NextUpgrade;
}

function InitFor(Sentinel S)
{
	Sentinel = S;
	PlaySound(ActivateSound);
}

function AddUpgrade(SentinelUpgrade NewUpgrade)
{
	if(NextUpgrade == None)
	{
		NextUpgrade = NewUpgrade;
		NextUpgrade.NextUpgrade = None;
	}
	else
		NextUpgrade.AddUpgrade(NewUpgrade);
}

simulated function SentinelUpgrade GetUpgrade(string getname)
{
    if (self.UpgradeName==getname)
        return self;
    if(NextUpgrade == None)
    	return none;
	else
		return NextUpgrade.GetUpgrade(getname);
}

//Called immediately after AddUpgrade and Sentinel.SWeapon has been set.
function ChangedWeapon()
{
	if(NextUpgrade != None)
		NextUpgrade.ChangedWeapon();
}

//Look after the linked list of upgrades.
function RemoveUpgrade(optional bool bRemoveAll)
{
	local SentinelUpgrade U;

	if(bRemoveAll)
	{
		if(NextUpgrade != None)
			NextUpgrade.RemoveUpgrade(true);
	}
	else if(Sentinel.Upgrade == self)
		Sentinel.Upgrade = NextUpgrade;
	else
	{
		for(U = Sentinel.Upgrade; U != None; U = U.NextUpgrade)
		{
			if(U.NextUpgrade == self)
			{
				U.NextUpgrade = NextUpgrade;
				break;
			}
		}
	}

	Destroy();
}

//A chance to modify damage taken by Sentinel.
function NotifyTakeDamage(out int Damage, Pawn EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType)
{
	if(NextUpgrade != None)
		NextUpgrade.NotifyTakeDamage(Damage, EventInstigator, HitLocation, Momentum, DamageType);
}

//Notification that a new enemy has been targeted.
function NewTarget(Pawn NewEnemy)
{
	if(NextUpgrade != None)
		NextUpgrade.NewTarget(NewEnemy);
}

//Sentinel fired its weapon.
function Fired()
{
	if(NextUpgrade != None)
		NextUpgrade.Fired();
}

//Sentinel is idle.
function SetWaiting()
{
	if(NextUpgrade != None)
		NextUpgrade.SetWaiting();
}

//A chance to display some effects when damage is taken, or something.
function PlayHit()
{
	if(NextUpgrade != None)
		NextUpgrade.PlayHit();
}

//Called when the Sentinel is destroyed.
function Died()
{
	if(NextUpgrade != None)
		NextUpgrade.Died();
}

defaultproperties
{
     UpgradeName="This is the default name."
     bFitsFloor=True
     bFitsCeiling=True
     bHidden=True
     RemoteRole=ROLE_SimulatedProxy
     SoundVolume=255
     SoundRadius=128.000000
     TransientSoundVolume=0.500000
}
